https://leetcode.cn/problems/count-substrings-starting-and-ending-with-given-character/description/


class Solution {
public:
    long long countSubstrings(string s, char c) {


        long long cnt = 0;
        for (int i = 0; i < s.size(); i++)
            if (s[i] == c)
                cnt++;

        if (cnt == 1)
            return 1;

        if (cnt == 0)
            return 0;

        long long f = 1;
        long long sum = 0;
        for (long long i = 1; i <= cnt; i++)
        {
            sum = (long long)sum + i;
        }
        return sum;

    }
};